<div id="patternmanager">

    <fieldset class="eComplexPattern">
    
    	<input type="hidden" name="patternUri" value="<?php echo $this->patternUri; ?>">

        <legend id="eComplexPattern-title">ComplexPattern</legend>
        
        <div class="row-input input-justify-left">
            <label for="label">Name</label>
            <input type="text" class="text" name="label" id="label" value="Pattername"/>
        </div>
        <div class="row-input input-justify-left">
            <label for="desc">Description</label>
            <input type="text" class="text" name="desc" id="desc" value="Patterndesc"/>
        </div>
        
		<p>
			Extended Options:
        	<a class="float-left icon icon-toggle-on" href="#" onclick="$('#eComplexPattern_extended_options').toggle(); $(this).toggleClass('icon-toggle-on'); $(this).toggleClass('icon-toggle-off'); return false;">
        		<span>show extended options</span>
    		</a>
		</p>
    	<div style="display:none;" id="eComplexPattern_extended_options">
    		<div class="row-input input-justify-left">
            	<label for="pattern-lvl">Pattern Level</label>
            	<select  name="pattern-lvl" id="pattern-lvl" size="1">
            		<option value=""><?php echo $this->_('select no value'); ?></option>
                    <option value="Syntactic">Syntactic</option>
                    <option value="Entity">Entity</option>
                    <option value="Instance/Data">Instance/Data</option>
                    <option value="Ontology">Ontology</option>
                </select>
                <script type="text/javascript">
                	// init annotations (level)
                	$('select#pattern-lvl option[value="<?php echo isset($this->annotations['lvl']) ? $this->annotations['lvl'] : '';?>"]').attr('selected', true);
                </script>
        	</div>
    		<div class="row-input input-justify-left">
            	<label for="pattern-term_state">Pattern State</label>
            	<select name="pattern-term_state" id="pattern-term_state" size="1">
            		<option value="null"><?php echo $this->_('select no value'); ?></option>
                    <option value="stable">stable</option>
                    <option value="testing">testing</option>
                </select>
                <script type="text/javascript">
                	// init annotations (state of term)
                	$('select#pattern-term_state option[value="<?php echo isset($this->annotations['term_state']) ? $this->annotations['term_state'] : '';?>"]').attr('selected', true);
                </script>
        	</div>
    	</div>

        <fieldset class="eSubpattern subpattern-hidden" style="display:none;">
            <legend>
                <a class="icon icon-toggle-on" href="javascript:showPMPattern();"><span>open</span></a><a class="icon icon-toggle-off" href="javascript:hidePMPattern();"><span>close</span></a>
                Subpattern
                <a class="icon icon-delete" href="javascript:delPMPattern();" title="Delete this Subpattern"><span>Delete this Subpattern</span></a>
                <a class="icon icon-copy PMcopyVar" title="Copy vars from this Subpattern"><span>Copy vars from this Subpattern</span></a>
            </legend>

            <div class="subfieldsetbody">

                <!-- a class="minibutton" href="javascript:hidePMPattern();">hide</a>
                <a class="minibutton" href="javascript:showPMPattern();">show</a>
                <a class="minibutton" href="javascript:delPMPattern();">del</a>
                <a class="minibutton PMcopyVar">copy vars from ... </a -->

                <!-- Name, Description -->

                <div class="row-input input-justify-left">
                    <label for="">Name</label>
                    <input type="text" class="BasicPattern text" name="patternlabel-" id="patternlabel-" value=""/>
                </div>
                <div class="row-input input-justify-left">
                    <label for="">Description</label>
                    <input type="text" class="text" name="patterndesc-" id="patterndesc-" value=""/>
                </div>

                <!-- Variablen -->

                <table class="vars">
                    <colgroup>
                        <col width="27%">
                        <col width="20%">
                        <col width="40%">
                        <col width="13%">
                    </colgroup>
                    <thead>
                        <tr>
                            <th><label>Variablename</label></th>
                            <th><label>Variabletype</label></th>
                            <th><label>Variabledescription</label></th>
                            <th class="onlyAural">Aktion</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <td colspan="4">
                                <a class="icon icon-add" href="javascript:addPMvar();" title="Add variable"><span>Add variable</span></a>
                            </td>
                        </tr>
                    </tfoot>
                    <tbody>
                        <tr>
                            <td>
                                <input class="text width95 eVarname" type="text" name="varname-" id="varname-"/>
                            </td>
                            <td>
                                <select  name="vartype-" id="vartype-" size="1">
                                    <option>RESOURCE</option>
                                    <option>LITERAL</option>
                                    <option>TEMP</option>
                                    <option>GRAPH</option>
                                    <option>LANG</option>
                                    <option>DATATYPE</option>
                                    <option>CLASS</option>
                                    <option>PROPERTY</option>
                                </select>
                            </td>
                            <td>
                                <input class="text width99 eVardesc" type="text" name="vardesc-" id="vardesc-"/>
                            </td>
                            <td>
                                <a class="icon icon-delete" href="javascript:delPMvar();" title="Delete variable"><span>Delete variable</span></a>
                            </td>
                        </tr>
                    </tbody>
                </table>

                <!-- Select Queries -->

                <table class="selectqueries">
                    <colgroup>
                        <col width="87%">
                        <col width="13%">
                    </colgroup>
                    <thead>
                        <tr>
                            <th><label>Select Query</label></th>
                            <th class="onlyAural">Aktion</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <td colspan="2">
                                <a class="icon icon-add" title="Add Query" style="display:none;" href="javascript:addPMselect();"><span>Add Query</span></a>
                            </td>
                        </tr>
                    </tfoot>
                    <tbody>
                        <tr>
                            <td>
                                <input class="text width99" type="text" name="selectpattern-" id="selectpattern-"/>
                            </td>
                            <td>
                                <a class="icon icon-delete" title="Delete Query" href="javascript:delPMselect();"><span>Delete Query</span></a>
                            </td>
                        </tr>
                    </tbody>
                </table>

                <!-- Insert Triples -->

                <table class="triplesInsert">
                    <colgroup>
                        <col width="87%">
                        <col width="13%">
                    </colgroup>
                    <thead>
                        <tr>
                            <th>Insert Triples</th>
                            <th class="onlyAural">Aktion</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <td colspan="2">
                                <a class="icon icon-add" title="Add triple to insert" href="javascript:addPMinsert();"><span>Add triple to insert</span></a>
                            </td>
                        </tr>
                    </tfoot>
                    <tbody>
                        <tr>
                            <td>
                                <input class="text width99" type="text" name="insertpattern-" id="insertpattern-"/>
                            </td>
                            <td>
                                <a class="icon icon-delete" title="Delete triple" href="javascript:delPMinsert();"><span>Delete triple</span></a>
                            </td>
                        </tr>
                    </tbody>
                </table>

                <!-- Delete Triples -->

                <table class="triplesDelete">
                    <colgroup>
                        <col width="87%">
                        <col width="13%">
                    </colgroup>
                    <thead>
                        <tr>
                            <th>Delete Triples</th>
                            <th class="onlyAural">Aktion</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <td colspan="2">
                                <a class="icon icon-add" title="Add triple to delete" href="javascript:addPMdelete();"><span>Add triple to delete</span></a>
                            </td>
                        </tr>
                    </tfoot>
                    <tbody>
                        <tr>
                            <td>
                                <input class="text width99" type="text" name="deletepattern-" id="deletepattern-"/>
                            </td>
                            <td>
                                <a class="icon icon-delete" title="Delete triple" href="javascript:delPMdelete();"><span>Delete triple</span></a>
                            </td>
                        </tr>
                    </tbody>
                </table>


            </div>
        </fieldset>


    </fieldset>

    <a id="buttonAddSubpattern" class="button" href="javascript:addPMPattern();"><?php echo $this->_('add subpattern');?></a>

</div>
<?php if ( !empty($this->jsonPattern) && is_string($this->jsonPattern) )  { ?>
<script type="text/javascript">
// jQuery Json used here (compatible)
var jsonPattern = $.secureEvalJSON(<?php echo Zend_Json::encode($this->jsonPattern); ?>);

label = jsonPattern['label'];
desc = jsonPattern['desc'];

$('div#patternmanager input#label').val(label);
$('div#patternmanager > fieldset > legend#eComplexPattern-title').html("ComplexPattern &quot;"+label+"&quot;");
$('div#patternmanager input#desc').val(desc);

for (key in jsonPattern['subPattern']) {

    label = jsonPattern['subPattern'][key]['label'];
    desc  = jsonPattern['subPattern'][key]['desc'];
    
    addPMPattern(label,desc);

    i = parseInt(key) + 1;
    current = jsonPattern['subPattern'][key];
    
    delPMvar(i,1);
    delPMselect(i,1);            
    delPMinsert(i,1);
    delPMdelete(i,1);
    
    for (t in current) {
        if (t == 'V') {
            
            for (v in current[t]) {
                addPMvar(i,null,current[t][v]['name'],current[t][v]['type'],current[t][v]['desc']);
            }
        } else if (t == 'S' && current[t] != null) {
            	addPMselect(i,null,current[t]);
        } else if (t == 'U') {
            for (pkey in current[t]) {
                if (current[t][pkey]['type'] === 'insert' ) {
                    addPMinsert(i, null, current[t][pkey]['pattern']);
                } else if ( current[t][pkey]['type'] === 'delete' ) {
                    addPMdelete(i, null, current[t][pkey]['pattern']);
                } else {
                    // do nothing (undefined type)
                }
            }
        }
    }
}
</script>

<?php } ?>
<?php if ( !empty($this->error) && is_string($this->error) )  { ?>
<script type="text/javascript">
// jQuery Json used here (compatible)
var errorpattern = $.secureEvalJSON(<?php echo Zend_Json::encode($this->error); ?>);
for (i in errorpattern) {
    $('#' + errorpattern[i]).css('background-color','#FF7070').css('color','#FAFAFA');
}
</script>

<?php } ?>

